import java.util.Random;

public class CommunityChest {

	private static String[] communityChestCard =  { "images/Community Chest Cards/01 - Bank error.png", "images/Community Chest Cards/02 - Pay hospital.png",
			 								"images/Community Chest Cards/03 - Beauty contest.png", "images/Community Chest Cards/04 - Income tax refund.png",
			 								"images/Community Chest Cards/05 - Fine or Chance.png", "images/Community Chest Cards/06 - Insurance Premium.png", 
			 								"images/Community Chest Cards/07 - Sold stock.png" , "images/Community Chest Cards/08 - Preference shares.png",
			 								"images/Community Chest Cards/09 - Advance to Go.png" , "images/Community Chest Cards/10 - Go to Old Kent Road.png",
			 								"images/Community Chest Cards/11 - Out of jail free.png", "images/Community Chest Cards/12 - Birthday.png",
			 								"images/Community Chest Cards/13 - Doctor's fee.png" , "images/Community Chest Cards/14 - Annuity matures.png",
			 								"images/Community Chest Cards/15 - Go to jail.png", "images/Community Chest Cards/16 - Inherit money.png",
			 								"images/Community Chest Cards/00 - Community Chest.png"};
	
	private static int pick;
	private static boolean jailCard = false;
	
		
	public static boolean getJailCard() {
		
		return jailCard;
	}

	public static void setJailCard(boolean jailCard) {
		
		CommunityChest.jailCard = jailCard;
	}

	public static void drawCard() {
	
		Random draw = new Random();
		CommunityChest.setPick(draw.nextInt(16));
	}
	
	public static Player implementCard(Player a) {
		
		switch(CommunityChest.getPick()) {
		
			case 0:
				a = bankError(a);
				break;
			case 1:
				a = payHospital(a);
				break;
			case 2:
				a = beautyContest(a);
				break;
			case 3:
				a = incomeTaxRefund(a);
				break;
			case 4:
				a = fineOrChance(a);
				break;
			case 5:
				a = insurancePremium(a);
				break;
			case 6:
				a = soldStock(a);
				break;
			case 7:
				a = preferenceShares(a);
				break;
			case 8:
				a = advanceToGo(a); 
				break;
			case 9:	
				a = goToOldKentRoad(a);
				break;
			case 10:
				a = outOfJailFree(a);
				break;
			case 11:
				a = birthday(a);
				break;
			case 12:
				a = doctorsFee(a);
				break;
			case 13:
				a = annuityMatures(a);
				break;
			case 14:
				a = goToJail(a);
				break;
			case 15:
				a = inheritMoney(a);
				break;
		}
		
		return a;
	}
	
	public static void setPick(int pick) {
		
		CommunityChest.pick = pick;
	}
	
	public static int getPick() {
		
		return pick;
	}
	
	public static Player bankError(Player a) {
		
		a.setCash(a.getCash()+200);
		
		return a;
	}
	
	public static Player payHospital(Player a) {
		
		if (a.getCash() >= 100) {
	
			a.setCash(a.getCash()-100);
		}
		
		else {
			
			//PROMPT
		}
		
		return a;
	}
	
	public static Player beautyContest(Player a) {
		
		if (a.getCash() >= 10) {
	
			a.setCash(a.getCash()-10);
		}
		
		else {

			//PROMPT
		}	
	
		return a;
	}
	
	public static Player incomeTaxRefund(Player a) {
		
		a.setCash(a.getCash()+20);
		
		return a;
	}
	
	public static Player fineOrChance(Player a) {
		
		if (a.getCash() >= 20) {

			//Fine: 20
		}
		
		else {
			
			//PROMPT
		}
		
		return a;
	}
		
	public static Player insurancePremium(Player a) {
		
		if (a.getCash() >= 50) {
		
			a.setCash(a.getCash()-50);
		
		}
		
		else {
			
			//PROMPT
		}
		
		return a;
	}
	
	public static Player soldStock(Player a) {
		
		a.setCash(a.getCash()+50);
		
		return a;
	}
	
	public static Player preferenceShares(Player a) {
		
		a.setCash(a.getCash()+25);
		
		return a;
	}
	
	public static Player advanceToGo(Player a) {
		
		Location.setRelocate(true);
		a.setStop(40);
		
		return a;
	}
	
	public static Player goToOldKentRoad(Player a) {
		
		Location.setRelocate(true);
		
		if (a.getCurrLoc() > LotTiles.OKR.getLocation()) {
			
			a.setStop(LotTiles.OKR.getLocation()+40);
		}
		
		else {
			
			a.setStop(LotTiles.OKR.getLocation());
		}
		
		return a;
	}
	
	public static Player outOfJailFree(Player a) {
		
		a.setOutOfJailCard2(true);
		
		return a;
	}
	
	public static Player birthday(Player a) {
		
		for (int x = 0; x < 8; x++) {
			
			a.setCash(a.getCash()+10);
		}
		
		return a;
	}
	
	public static Player doctorsFee(Player a) {
		
		if (a.getCash() >= 50) {
		
			a.setCash(a.getCash()-50);
		}
		
		else {
			
			//PROMPT
		}
		
		return a;
	}
	
	public static Player annuityMatures(Player a) {
		
		a.setCash(a.getCash()+100);
		
		return a;
	}
	
	public static Player goToJail(Player a) {
		
		a.setJail(true);
		
		return a;
	}
	
	public static Player inheritMoney(Player a) {
		
		a.setCash(a.getCash()+100);
		
		return a;
	}
	
	public static String getCommunityChestURL(int x) {
		
		return communityChestCard[x];
	}
	
}